package com.sgxy.wmservice.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sgxy.commonutils.R;
import com.sgxy.wmservice.entity.WmGoodsType;
import com.sgxy.wmservice.entity.WmOutputOrder;
import com.sgxy.wmservice.entity.WmStore;
import com.sgxy.wmservice.entity.vo.OutputOrderVo;
import com.sgxy.wmservice.entity.vo.StoreVo;
import com.sgxy.wmservice.service.WmStoreService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author testjava
 * @since 2022-04-29
 */
@RestController
@RequestMapping("/wmservice/wmstore")
public class WmStoreController {
    @Autowired
    private WmStoreService wmStoreService;

    @PostMapping("{page}/{limit}")
    public R index(@PathVariable Long page,
                   @PathVariable Long limit,
                   @RequestBody(required = false) WmStore wmStore){
        Page<StoreVo> storePage = new Page<>(page,limit);
        wmStoreService.selectPageVoList(storePage, wmStore);

        return R.ok().data("items",storePage.getRecords()).data("total",storePage.getTotal());
    }

    @GetMapping("getStoreAll")
    public R getStoreAll(){
        List<WmStore> list = wmStoreService.list(null);
        return R.ok().data("list",list);
    }

    @GetMapping("getStoreInfoById/{id}")
    public R getStoreInfoById(@PathVariable String id){
        StoreVo storeVo = wmStoreService.getStoreInfoById(id);
        return R.ok().data("storeVo",storeVo);
    }

    //添加
    @PostMapping("addStore")
    public R addStore(@RequestBody WmStore wmStore){
        wmStoreService.save(wmStore);
        return R.ok();
    }
    //更新
    @PostMapping("updateStore")
    public R updateStore(@RequestBody WmStore wmStore){
        wmStoreService.updateById(wmStore);
        return R.ok();
    }
    //删除
    @DeleteMapping("{id}")
    public R deleteStore(@PathVariable String id){
        wmStoreService.deleteStore(id);
        return R.ok();
    }

}

